//
//  SoundTouchC.h
//  OWLDoorRing
//
//  Created by QiuDong on 2018/9/10.
//

#ifndef SoundTouchC_h
#define SoundTouchC_h

typedef short SAMPLETYPE;
typedef unsigned int uint;

/// Soundtouch library version string
#define SOUNDTOUCH_VERSION          "1.7.1"

/// SoundTouch library version id
#define SOUNDTOUCH_VERSION_ID       (10701)

//
// Available setting IDs for the 'setSetting' & 'get_setting' functions:

/// Enable/disable anti-alias filter in pitch transposer (0 = disable)
#define SETTING_USE_AA_FILTER       0

/// Pitch transposer anti-alias filter length (8 .. 128 taps, default = 32)
#define SETTING_AA_FILTER_LENGTH    1

/// Enable/disable quick seeking algorithm in tempo changer routine
/// (enabling quick seeking lowers CPU utilization but causes a minor sound
///  quality compromising)
#define SETTING_USE_QUICKSEEK       2

/// Time-stretch algorithm single processing sequence length in milliseconds. This determines
/// to how long sequences the original sound is chopped in the time-stretch algorithm.
/// See "STTypes.h" or README for more information.
#define SETTING_SEQUENCE_MS         3

/// Time-stretch algorithm seeking window length in milliseconds for algorithm that finds the
/// best possible overlapping location. This determines from how wide window the algorithm
/// may look for an optimal joining location when mixing the sound sequences back together.
/// See "STTypes.h" or README for more information.
#define SETTING_SEEKWINDOW_MS       4

/// Time-stretch algorithm overlap length in milliseconds. When the chopped sound sequences
/// are mixed back together, to form a continuous sound stream, this parameter defines over
/// how long period the two consecutive sequences are let to overlap each other.
/// See "STTypes.h" or README for more information.
#define SETTING_OVERLAP_MS          5


/// Call "getSetting" with this ID to query nominal average processing sequence
/// size in samples. This value tells approcimate value how many input samples
/// SoundTouch needs to gather before it does DSP processing run for the sample batch.
///
/// Notices:
/// - This is read-only parameter, i.e. setSetting ignores this parameter
/// - Returned value is approximate average value, exact processing batch
///   size may wary from time to time
/// - This parameter value is not constant but may change depending on
///   tempo/pitch/rate/samplerate settings.
#define SETTING_NOMINAL_INPUT_SEQUENCE        6


/// Call "getSetting" with this ID to query nominal average processing output
/// size in samples. This value tells approcimate value how many output samples
/// SoundTouch outputs once it does DSP processing run for a batch of input samples.
///
/// Notices:
/// - This is read-only parameter, i.e. setSetting ignores this parameter
/// - Returned value is approximate average value, exact processing batch
///   size may wary from time to time
/// - This parameter value is not constant but may change depending on
///   tempo/pitch/rate/samplerate settings.
#define SETTING_NOMINAL_OUTPUT_SEQUENCE        7

typedef struct SoundTouchHandleStruct {
    void* _impl;
} SoundTouchHandle;

#ifdef __cplusplus
extern "C" {
#endif

    bool createSoundTouch(SoundTouchHandle* pHandle);
    
    void releaseSoundTouch(SoundTouchHandle* pHandle);
    
    void soundtouchSetRate(SoundTouchHandle* pHandle, float newRate);
    
    void soundtouchSetTempo(SoundTouchHandle* pHandle, float newTempo);
    
    void soundtouchSetRateChange(SoundTouchHandle* pHandle, float newRate);
    
    void soundtouchSetTempoChange(SoundTouchHandle* pHandle, float newTempo);
    
    void soundtouchSetPitch(SoundTouchHandle* pHandle, float newPitch);
    
    void soundtouchSetPitchOctaves(SoundTouchHandle* pHandle, float newPitch);
    
    void soundtouchSetPitchSemiTonesI(SoundTouchHandle* pHandle, int newPitch);
    
    void soundtouchSetPitchSemiTonesF(SoundTouchHandle* pHandle, float newPitch);
    
    void soundtouchSetChannels(SoundTouchHandle* pHandle, uint numChannels);
    
    void soundtouchSetSampleRate(SoundTouchHandle* pHandle, uint srate);
    
    void soundtouchFlush(SoundTouchHandle* pHandle);
    
    void soundtouchPutSamples(SoundTouchHandle* pHandle, const SAMPLETYPE *samples, uint numSamples);
    
    uint soundtouchReceiveSamples(SoundTouchHandle* pHandle, SAMPLETYPE* outBuffer, uint maxSamples);
    
    void soundtouchClear(SoundTouchHandle* pHandle);
    
    bool soundtouchSetSetting(SoundTouchHandle* pHandle, int settingId, int value);
    
    int soundtouchGetSetting(SoundTouchHandle* pHandle, int settingId);
    
    uint soundtouchNumUnprocessedSamples(SoundTouchHandle* pHandle);
    
#ifdef __cplusplus
}
#endif

#endif /* SoundTouchC_h */
